﻿using Microsoft.Extensions.Caching.Distributed;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Tingjian.gas.service.Utility.CommonUtility
{
    public class RedisPolicyHelper
    {

        /// <summary>
        /// 使用绝对还是滑动过期，不使用策略就默认为长期保存
        /// </summary>
        /// <param name="ab_hd">true绝对过期; false:滑动过期</param>
        /// <param name="Seconds">默认60秒过期</param>
        /// <returns></returns>
        public static DistributedCacheEntryOptions GetRedisProcily(bool isAbsolute, int Seconds = 60)
        {
            var policy = new DistributedCacheEntryOptions();
            Seconds = Seconds <= 1 ? 60 : Seconds;
            if (isAbsolute)
                policy.AbsoluteExpirationRelativeToNow = TimeSpan.FromSeconds(Seconds);
            else
                policy.SlidingExpiration = TimeSpan.FromSeconds(Seconds);

            return policy;
        }
    }
}
